package main

import (
	"fmt"
	"gitee.com/gorm"
	_ "gitee.com/gorm/dialects/mysql"
	"time"
)

var db *gorm.DB

func init() {
	var err error
	db, err = gorm.Open("mysql", "jyzk:jyzk36801580@tcp(127.0.0.1:3306)/dcs?charset=utf8&parseTime=True&loc=Local")
	if err != nil {
		panic(err)
	}
}

type Product struct {
	gorm.Model
	Code       string
	Price      uint
	Name       string
	Factory_no string
}

type Base_machine struct {
	Tid                uint64
	Machine_no         string
	Machine_ip         string
	Spindle_count      string
	Spindle_speed      string
	Front_roller_speed string
	Standard_twist     string
	Rear_roller_speed  string
	Dtime              string
	Uploaded           int8
	Upload_time        string
}

func main_() {

	defer db.Close()

	//var machines[] Base_machine
	//if len(machines) > 0 {
	//
	//	for i:=0; i< len(machines); i++{
	//		fmt.Println(machines[i])
	//	}
	//}

	//db.Table("base_machine").Find(&machines)
	//rows, err := db.Table("base_machine").Select("tid, machine_no, machine_ip, spindle_mode, spindle_speed").Rows()
	rows, err := db.Table("base_machine").Rows()
	if err != nil {
		panic(err)
		return
	}
	var macs []Base_machine

	for rows.Next() {
		var mac Base_machine
		db.ScanRows(rows, &mac)
		macs = append(macs, mac)
		fmt.Println(mac)
	}

	rows.Close()
	//db.AutoMigrate(&Product{})
	//db.Create(&Product{Code:"L1212", Price:1000, Name:"apple"})
	//var product Product
	//
	//db.First(&product, 1)
	//db.First(&product, "code = ?", "L1212")
	//
	//db.Model(&product).Update("Price", 2000)

}

func main() {
	current := time.Now().Format("2006-01-02 15:04:05")
	fmt.Println(current)
}
